<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ include file="/common/taglibs.jsp"%>
<%@ taglib prefix="wf" uri="/augurit-wf"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script src="${ctx}/gzcgwsp/resources/js/YwEnterprise.js" type="text/javascript"></script>
<script type="text/javascript">
var saveAndSendFlag = undefined;

$(document).ready(function(){
  $('form[0]').ajaxForm({
    dataType: 'json', 
    success: wfBusSaveCallback
  });
});

function wfBusSaveCallback(result){
  var success = window.updateLayoutAfterWfBusSave(result, false);
  
  if(success){
    if (result && result.form) {
      WF_CONFIG.masterEntityKey = result.form.id;
      document.forms[0].id.value = result.form.id;
      document.forms[0].qyid.value = result.form.qyid;
      document.forms[0].acceptNo.value = result.form.acceptNo;
      document.forms[0].acceptNo_.value = result.form.acceptNo;
      
      document.getElementById('sjcl_iframe').src = '${ctx}/yw-com-sjcllist!ywList.action?tplcode=${templateCode}&ajid=' + result.form.id + '&qyid=' + result.form.qyid;
      
      if (Ext.getCmp('sjclPanel')) Ext.getCmp('sjclPanel').setDisabled(false);
      if (Ext.getCmp('gisPanel')) Ext.getCmp('gisPanel').setDisabled(false);
      
      if (Ext.getCmp('WF_PRINT')) Ext.getCmp('WF_PRINT').setDisabled(false);
      
      saveOpinion();
    }
    
    if(saveAndSendFlag == 'wfBusSaveAndSend') {
      var toolbar = Ext.getCmp('WF_TOOLBAR');
      if(toolbar) toolbar.wfSend();
    }
    if(saveAndSendFlag == 'wfBusSave') {
      alert('保存成功！');
    }
    if(saveAndSendFlag == 'wfBusSj') {
      if (opener.refresh) opener.refresh();
      Ext.getCmp('YslSjBtn').setDisabled(true);
      Ext.getCmp('YslTuihBtn').setDisabled(true);
      alert('收件成功！');
    }
    if(saveAndSendFlag == 'wfBusYslTuih') {
      if (opener.refresh) opener.refresh();
      window.close();
    }
  }
}

function wfBusSaveAndSend(templateCode, taskInstDbid){
  saveAndSendFlag = 'wfBusSaveAndSend';
  if(validateSend()){
    $('form[0]').attr('action', '${ctx}/yw-hw-sh-sqb!wfBusSave.action?templateCode='+templateCode+'&taskInstDbid='+taskInstDbid);
    $('form[0]').submit();
  }
}

function wfBusSave(templateCode, taskInstDbid){
  saveAndSendFlag = 'wfBusSave';
  if(validateForm()){
    $('form[0]').attr('action', '${ctx}/yw-hw-sh-sqb!wfBusSave.action?templateCode='+templateCode+'&taskInstDbid='+taskInstDbid);
    $('form[0]').submit();
  }
}

function wfBusSj() {
  saveAndSendFlag = 'wfBusSj';
  if(validateForm()){
    $('form[0]').attr('action', '${ctx}/yw-hw-sh-sqb!wfBusSave.action?templateCode='+WF_CONFIG.templateCode+'&isYsl=1');
    $('form[0]').submit();
  }
}

function wfBusYslTuih() {
  saveAndSendFlag = 'wfBusYslTuih';
  if(validateForm()){
    $('form[0]').attr('action', '${ctx}/yw-hw-sh-sqb!wfBusYslTuih.action?templateCode='+WF_CONFIG.templateCode+'&isYsl=1');
    $('form[0]').submit();
  }
}

function CreateDoc(){
  var win = new Ext.ux.wf.WfSelRedHeadFile({
    url: '/yw-hw-sh-sqb!makeDocument.action'
  });
  win.show();
}

function printcz(){
  var busEntityKey = document.forms[0].id.value;
  
  if(busEntityKey != null && busEntityKey != '') {
    var url = '${ctx}/yw-com-print!taskInfo.action?id='+busEntityKey + '&templateCode=' + WF_CONFIG.templateCode;
    YwUtil.openWin({url: url, w: 500, h: 400});
  }
}

function saveOpinion() {
    var jbrTxt = document.getElementById('jbrJudgmentTxt_hw');
    var deptTxt = document.getElementById('deptJudgmentTxt_hw');
    var lsTxt = document.getElementById('leadershipJudgmentTxt_hw');
    
    var inputObj, divobj;
    if (jbrTxt && !deptTxt && !lsTxt) {
      inputObj = jbrTxt; divobj = document.getElementById('jbrJudgment');
    } else
    if (!jbrTxt && deptTxt && !lsTxt) {
      inputObj = deptTxt; divobj = document.getElementById('deptJudgment');
    } else
    if (!jbrTxt && !deptTxt && lsTxt) {
      inputObj = lsTxt; divobj = document.getElementById('leadershipJudgment');
    }
    
    if (!inputObj || inputObj.value == '') return;
    
    Ext.Ajax.request({
      method:'post',
      url:'${ctx}/wf!saveTaskOpinion.action',
      params:{
        'instance.taskInstDbid': WF_CONFIG.taskInstDbid,
        'instance.handleComments': inputObj.value
      },
      success:function(){
      changeOpinion(inputobj.value, divobj);
        inputobj.value = '';
      },
      scope:this
    });
}

function writeJudgment(index) {
    var divid = '';
    switch(index) {
        case 'A': divid = 'jbrJudgment'; break;
        case 'B': divid = 'deptJudgment'; break;
        case 'C': divid = 'leadershipJudgment'; break;
        case 'E': divid = 'deptJudgmentYQ'; break;
        case 'F': divid = 'leadershipJudgmentYQ'; break;
    }
    var divobj = document.getElementById(divid);
    if (divid == '' || !divobj) {
        alert('参数错误！');
        return;
    }
    var win = new Ext.ux.wf.WfOpinionWin({
        taskInstDbid: Ext.getCmp('WF_TOOLBAR').taskInstDbid
    });
    win.show();
    win.on('complete', function (opinion) {
    changeOpinion(opinion, divobj); 
    });
}

function inputJudgment(index) {
    var divid = '', inputid = '';
    switch(index) {
        case 'A': divid = 'jbrJudgment'; inputid = 'jbrJudgmentTxt_hw'; break;
        case 'B': divid = 'deptJudgment'; inputid = 'deptJudgmentTxt_hw'; break;
        case 'C': divid = 'leadershipJudgment'; inputid = 'leadershipJudgmentTxt_hw'; break;
        case 'E': divid = 'deptJudgmentYQ'; inputid = 'deptJudgmentTxt_hwYQ'; break;
        case 'F': divid = 'leadershipJudgmentYQ'; inputid = 'leadershipJudgmentTxt_hwYQ'; break;
    }
    var divobj = document.getElementById(divid);
    var inputobj = document.getElementById(inputid);
    if (divid == '' || !divobj) {
        alert('参数错误！');
        return;
    }
    if (inputobj.value == '') { alert('请输入意见!'); return; }
    
    Ext.Ajax.request({
      method:'post',
      url:'${ctx}/wf!saveTaskOpinion.action',
      params:{
        'instance.taskInstDbid': WF_CONFIG.taskInstDbid,
        'instance.handleComments': inputobj.value
      },
      success:function(){
      changeOpinion(inputobj.value, divobj);
        inputobj.value = '';
       
      },
      scope:this
    });
}

function changeOpinion(opinion, divobj) {
  var userOpinion = document.getElementById('userOpinion');
  if (userOpinion) {
    userOpinion.innerHTML = opinion + '<br>&nbsp;&nbsp;&nbsp;&nbsp;${CurrUserName}&nbsp;&nbsp;' + new Date().format('yyyy-MM-dd hh:mm:ss');
  } else {
    divobj.style.color = '#009966';
    divobj.innerHTML = opinion + '<br>&nbsp;&nbsp;&nbsp;&nbsp;${CurrUserName}&nbsp;&nbsp;' + new Date().format('yyyy-MM-dd hh:mm:ss');
  }
 
}

Ext.onReady(function(){
    var id_ = document.forms[0].id.value;
    var acceptNo_ = document.forms[0].acceptNo.value;
    
    if (id_ == '') {
      if (Ext.getCmp('WF_PRINT')) Ext.getCmp('WF_PRINT').setDisabled(true);
    }
    
    var centerTabPanel = Ext.getCmp('centerPanel');
    var ywPanel = new Ext.TabPanel({
        id: 'YwHwShSqbTpanel',
        renderTo: 'tpanel',
        activeTab: 3,
        border: false,
        height: centerTabPanel.getHeight(),
        enableTabScroll: true,
        defaults: {autoScroll: true},
        items: [
            //new Ext.Panel({id: 'gisPanel', title: 'WEBGIS', tabCls: 'right-tab', contentEl: 'gis_tpanel', border: false, disabled: id_ == '' ? true : false}),
            //new Ext.Panel({id: 'sjclPanel', title: '收件材料', tabCls: 'right-tab', contentEl: 'sjcl_tpanel', border: false, disabled: id_ == '' ? true : false}),
            //new Ext.Panel({title: '延期表', tabCls: 'right-tab', contentEl: 'tpanel05', border: false, disabled: id_ == '' ? true : false}),
            //new Ext.Panel({title: '基本信息', tabCls: 'right-tab', contentEl: 'tpanel01', border: false}),
            //new Ext.Panel({title: '呈批表', tabCls: 'right-tab', contentEl: 'tpanel02', border: false})
        ],
        listeners: {
            remove: function(tp, c) {
                c.hide();
            },
            afterlayout: function(c) {
                c.strip.setWidth(c.stripWrap.getWidth() - 2);
            },
            tabchange : function (tpanel, p) { }
        }
    });
    var cpbPanel = new Ext.Panel({title: '呈批表', tabCls: 'right-tab', contentEl: 'tpanel02', border: false});
    var jbxxPanel = new Ext.Panel({title: '基本信息', tabCls: 'right-tab', contentEl: 'tpanel01', border: false});
    
    if (<wf:hasPriv activities="jbrsl,czgldsh,cfgldsh,wfgldsh,wzgldsp,jbrsj,dzgz,czgldyqsh,wzgldyqsh,jbrslyqbl" />) {//1
        ywPanel.add(new Ext.Panel({id: 'gisPanel', title: 'WEBGIS', tabCls: 'right-tab', contentEl: 'gis_tpanel', border: false, disabled: id_ == '' ? true : false}));
    }
    
    if (<wf:hasPriv activities="cksa,jbrsl,czgldsh,cfgldsh,wfgldsh,wzgldsp,jbrsj,dzgz,czgldyqsh,wzgldyqsh,jbrslyqbl" />) {//2
        ywPanel.add(new Ext.Panel({id: 'sjclPanel', title: '收件材料', tabCls: 'right-tab', contentEl: 'sjcl_tpanel', border: false, disabled: id_ == '' ? true : false}));
        ywPanel.add(jbxxPanel);
    }
    
    if (<wf:hasPriv activities="czgldyqsh,wzgldyqsh,jbrslyqbl" />) {
        ywPanel.add(new Ext.Panel({title: '延期表', tabCls: 'right-tab', contentEl: 'tpanel05', border: false, disabled: id_ == '' ? true : false}));
    }
    
    if (<wf:hasPriv activities="jbrsl,czgldsh,cfgldsh,wfgldsh,wzgldsp,jbrsj,dzgz" />) {
        ywPanel.add(cpbPanel);
        ywPanel.setActiveTab(cpbPanel);
    } else {
        //ywPanel.add(cpbPanel);
        ywPanel.setActiveTab(jbxxPanel);
    }
    
    ywPanel.doLayout(true);
});
//电子盖章
function apabiPrint()
{
    var url = '${ctx}/yw-dzgz-list!listByAjid.action?ajid='+'${id}';
    YwUtil.openWin({url: url});
}
</script>
</head>

<body>

<form action="yw-hw-sh-sqb!save.action" method="post">
  <!---------------- 隐藏域区域 开始 ----------------->
  <input type="hidden" name="id" value="${id}" />
  <input type="hidden" name="qyid" value="${qyid}" />
  <!---------------- 隐藏域区域 结束 ----------------->
  
<div id="tpanel"></div>

<div style="display:none">
<div id="tpanel01" align="center"><%@ include file="YwHwShSqb-sqb.jsp" %></div>
<div id="tpanel02" align="center"><%@ include file="YwHwShSqb-cpb.jsp" %></div>
<div id="tpanel05" align="center"><%@ include file="YwHwShSqb-yqb.jsp" %></div>
<div id="gis_tpanel">
   <iframe src="${ctx}/flex/index.html" scrolling="auto" frameborder="0" width="100%" height="100%"></iframe>
</div>
<div id="sjcl_tpanel">
  <iframe id="sjcl_iframe" src="${ctx}/yw-com-sjcllist!ywList.action?tplcode=${templateCode}&ajid=${id}&qyid=${qyid}" scrolling="auto" frameborder="0" width="100%" height="100%"></iframe>
</div>
</div>
</form>
</body>
</html>
